// 运行时配置
import { RequestConfig, useRoutes } from "@umijs/max";

// 全局初始化数据配置，用于 Layout 用户信息和权限初始化
// 更多信息见文档：https://umijs.org/docs/api/runtime-config#getinitialstate
export async function getInitialState(): Promise<{ name: string }> {
  return { name: '@umijs/max' };
}

export const layout = () => {
  return {
    logo: 'https://img.alicdn.com/tfs/TB1YHEpwUT1gK0jSZFhXXaAtVXa-28-27.svg',
    menu: {
      locale: false,
    }
  };
};

export const request: RequestConfig = {
    requestInterceptors: [
      // 直接写一个 function，作为拦截器
      (url, options) =>
        {
            const user = localStorage.getItem('user') ? localStorage.getItem('user') as string : ''

            options.headers = {
                ...options.headers,
                user
            }
          // do something
          return { url, options }
        },
        (url,options) => {
          const env = process.env.NODE_ENV

          if(env !== 'development') {
            url = `http://118.145.215.27:9090`+url
          }

          return {
            url,
            options
          }
        }
    ]
  }
